<template>
    <h1>投资项目用户登录</h1>
    <table>
        <tr>
            <td>用户名</td>
            <td>
                <input type="text" v-model="Name" >
            </td>
        </tr>

        <tr>
            <td>密码</td>
            <td>
                <input type="password" v-model="Pwd" >
            </td>
        </tr>

        <tr>
            <td colspan="2">
                <input type="button" value="登录" @click="ILogin" >
            </td>
        </tr>

    </table>
</template>

<script setup lang="ts">

import {ref} from 'vue';
import axios from 'axios';
import {useStore} from '../../store/index'
import {useRouter} from 'vue-router'

const router = useRouter();

const Name = ref('');
const Pwd = ref('');

const store = useStore();

const ILogin = ()=>{
    axios({
        method:'get',
        url:'http://localhost:61480/api/Invest/ILogin',
        params:{
            Name:Name.value,
            Pwd:Pwd.value
        }
    })
    .then(res=>{
        console.log(res.data);
        store.Uid = res.data[0].UL_Id
        //alert(store.Uid)
        UserType(res.data[0].UL_Id);
    })
    .catch(err=>{
        console.log(err);
    })
}

const UserType = (UId:string) =>{
    axios({
        method:'get',
        url:'http://localhost:61480/api/Invest/UserType',
        params:{
            UId:UId
        }
    })
    .then(res=>{
        console.log(res.data);
        if(res.data[0].UT_Name=="用户"){
            alert("用户你好");
            router.push('/UserInvestShow');
        }
        else{
            alert("管理员你好");
            router.push('/AilShowInvest');
        }
    })
    .catch(err=>{
        console.log(err);
    })
}


</script>